#include <pthread.h>
#include "device/type.h"
#include "device/context.h"
#include "common/rc_status.h"
#include "common/log.h"

char g_runFlag = 1;

int main(int argc, char* argv[])
{
    Context* context = NULL;
    RCStatus status = ContextCreate(&context);;
    if (status != RC_SUCCESS) {
        LOG_ERROR("context create failed\n");
        return status;
    }

    while (g_runFlag) {
        status = CMDRecv(context);
        if (status != RC_SUCCESS) {
            return status;
        }

        status = ContextHandle(context);
        if (status != RC_SUCCESS) {
            LOG_WARN("handle context: 0x%p failed, status: 0x%x", context, status);
        }

        status = ACKSND(context);
        if (status != RC_SUCCESS) {
            LOG_WARN("ACKSND context: 0x%p failed, status: 0x%x", context, status);
        }

        LOG_INFO("cmd recv, handle and ack success");
    }

    ContextDestroy(&context);
    return 0;
}